//
//  JWStudentInfoCtry.m
//  koubei
//
//  Created by 李彦宏 on 2018/5/15.
//  Copyright © 2018年 朱圳. All rights reserved.
//

#import "JWStudentInfoCtry.h"
#import "StuUserCell.h"
#import "SDUserModel.h"
#import "JWUserManager.h"
#import "JWGRUsermodel.h"
#import "JWChooseGrSeachVC.h"//选择研究生搜索

@interface JWStudentInfoCtry ()<UITableViewDelegate,UITableViewDataSource,UIGestureRecognizerDelegate>

@property (nonatomic, strong) NSMutableArray *list;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) SDUserModel *model;
@property (nonatomic, strong) JWGRUsermodel *Gmodel;
@property (nonatomic, strong) NSMutableArray *GRarrylist;
@end

@implementation JWStudentInfoCtry

- (void)viewDidLoad {
    [super viewDidLoad];
    self.model=[JWUserManager SDme];
    [self.view addSubview:self.tableView];
    [self setBack];
    //研究生数据
    [self setGRdate];
    //加载plist文件
    NSString *path=[[NSBundle mainBundle]pathForResource:@"JWStHongPage" ofType:@"plist"];
    //存进数组里
    self.list =[NSMutableArray arrayWithContentsOfFile:path];
    
    
}
-(void)setBack{
    /*设置导航栏上面的内容*/
    UIButton *backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    // 设置图片
    [backBtn setBackgroundImage:[UIImage imageNamed:@"navigationbar_back"] forState:UIControlStateNormal];
    [backBtn setBackgroundImage:[UIImage imageNamed:@"navigationbar_back_highlighted"] forState:UIControlStateHighlighted];
    // 设置尺寸
    backBtn.size = backBtn.currentBackgroundImage.size;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    /**
     解决自定义返回 手势失效
     */
    self.navigationController.interactivePopGestureRecognizer.delegate=(id)self;
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    return 45;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.list.count;
}
-(void)tapAction{
    JWChooseGrSeachVC *vc=[[JWChooseGrSeachVC alloc]init];
    
    vc.tagsArray=[[NSMutableArray alloc]init];
    if(self.GRarrylist.count<7){
        vc.tagsArray=[NSMutableArray arrayWithObjects:@"李彦宏",@"朱圳",@"严戈闲",@"赵延",@"田涛",@"肖欢欣",@"游鹤亭",@"陈炽", nil];
        
    }else{
        for (int i=0; i<7; i++) {
            self.Gmodel=self.GRarrylist[i];
            [vc.tagsArray  addObject:self.Gmodel.name];
        }
    }
    [self.navigationController pushViewController:vc animated:YES];
    
}
#pragma -mark ——————————————Cell内容—————————————————
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        static NSString *CellIdentifier = @"stuUserCell";
        StuUserCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell == nil) {
            cell = [[StuUserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.nameLabel.text = self.list[indexPath.row][@"name"];
        cell.tximg.image = [UIImage imageNamed:self.list[indexPath.row][@"img"]];
        cell.dataText.textAlignment=NSTextAlignmentLeft;
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    tap.delegate=self;
    tap.numberOfTapsRequired=1;
    tap.numberOfTouchesRequired=1;
    
    if (indexPath.row == 10) {
        cell.dataText.text=@"选择研究生分配";
        cell.dataText.textColor=[UIColor redColor];
        [ cell.dataText addGestureRecognizer:tap];
        
    }else{
        cell.dataText.userInteractionEnabled=NO;
    }
    
        if (indexPath.row == 0) {
            cell.dataText.text = self.model.name;
        }
        if (indexPath.row == 1) {
            cell.dataText.text = self.model.phone;
        }
        if (indexPath.row == 2) {
            if ([self.model.sex isEqualToString:@"1"]) {
                cell.dataText.text = @"女";
            }else{
                cell.dataText.text = @"男";
            }
        }
        if(indexPath.row==3){
            if([self.model.xieyi isEqualToString:@"0"]){
                cell.dataText.text=@"否";
            }else{
                cell.dataText.text=@"是";
            }
        }
        if (indexPath.row == 4) {
            
            cell.dataText.text = self.model.college;
        }
        if (indexPath.row == 5) {
            cell.dataText.text = self.model.jieshu;
        }
        if (indexPath.row == 6) {
            cell.dataText.text = self.model.address;
        }
        if (indexPath.row == 7) {
            cell.dataText.text = self.model.math;
            
        }
        if (indexPath.row == 8) {
            cell.dataText.text = self.model.english;
        }
        
        if (indexPath.row == 9) {
            cell.dataText.text = self.model.goal;
        }
        if (indexPath.row == 11) {
            cell.dataText.text = self.model.QQ;
        }
        if (indexPath.row == 12) {
            cell.dataText.text = self.model.Winxin;
        }
        if (indexPath.row == 13) {
            cell.dataText.text = self.model.BirthDay;
            
        }
        if (indexPath.row == 14) {
            cell.dataText.text = self.model.dadphone;
        }
        if (indexPath.row == 15) {
            cell.dataText.text = self.model.mumphone;
        }
        if (indexPath.row == 16) {
            cell.dataText.text = self.model.BuyCourse;
        }
        if (indexPath.row == 17) {
            cell.dataText.text = self.model.classmoney;
        }
        
        if (indexPath.row == 18) {
            cell.dataText.text = self.model.Baiduyun;
        }
        if (indexPath.row == 19) {
            cell.dataText.text = self.model.Vyan;
        }
        return cell;
        
}

/** 区foot视图 */
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footer=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 120)];
    
    UILabel *lb1=[[UILabel alloc]init];
    lb1.text=@"邮寄书籍";
    lb1.textAlignment=NSTextAlignmentCenter;
    
    [footer addSubview:lb1];
    [lb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(footer);
        make.top.equalTo(footer.mas_top).offset(0);
        make.height.mas_equalTo(30);
    }];
    
    UITextView * text = [[UITextView alloc]init];
    text.text=self.model.mailbook;
    text.layer.borderWidth = 1;
    text.layer.borderColor = [UIColor orangeColor].CGColor;
    [footer addSubview:text];
    [text mas_makeConstraints:^(MASConstraintMaker *make) {
        [make.top.mas_equalTo(lb1.mas_bottom) setOffset:5];
        [make.left.mas_equalTo(footer.mas_left) setOffset:10];
        [make.right.mas_equalTo(footer.mas_right) setOffset:-10];
        make.size.height.mas_equalTo(80);
    }];
        text.userInteractionEnabled=NO;
    return footer;
}
/*******设置高度解决Button点击没效果*******/
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 120;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma -mark ————————————————研究生数据————————————————————
-(void)setGRdate{
    
    __weak typeof(self) weakslf = self;
    
    NSDictionary *dict=@{
                         @"jwid":JWid,
                         @"jwpassword":JWpassword,
                         @"page" :@"1",
                         };
    //    NSLog(@"--dict--%@", dict);
    //    参数  分页=>page 教务id=〉jwid ，秘码=>jwpassword
    [[AFNetworkTool shareManager]getJSONWithUrl:JWteacher_ChangeGR parame:dict successData:^(id json) {
        [self.GRarrylist removeAllObjects];
        NSArray * arr = json[@"data"];
        
        for(int i=0;i<arr.count;i++){
            
            self.Gmodel = [JWGRUsermodel yy_modelWithJSON:arr[i]];
            [JWUserManager saveGR:self.Gmodel];
            
            [weakslf.GRarrylist addObject: self.Gmodel ];
            
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakslf.tableView reloadData];
        });
    } failure:^(NSError *error) {
        NSLog(@"--error--%@", error);
    }];
    
}
-(NSMutableArray * )GRarrylist{
    if(_GRarrylist==nil){
        _GRarrylist=[[NSMutableArray alloc]init];
    }
    return _GRarrylist;
}
#pragma -mark ——————————————————懒加载————————————————————
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)style:UITableViewStyleGrouped];
        //隐藏组与导航栏间距
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor whiteColor];
        [_tableView registerClass:[StuUserCell class] forCellReuseIdentifier:@"stuUserCell"];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}


@end
